package com.wootion.cims.module.basicinformation.plotsetting.controller;
import com.wootion.cims.module.basicinformation.plotsetting.model.PlotMessage;
import com.wootion.cims.module.basicinformation.plotsetting.service.PlotSettingService;
import com.wootion.cims.module.systemsetting.dictionary.model.LogAnotion;
import com.wootion.cims.module.systemsetting.polt.model.SysPlot;
import com.wootion.cims.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: jack
 * @Date: 2022/12/02/13:59
 * @Description:
 */
@Api(value = "小区信息")
@RestController
@RequestMapping(path = {"/plotsetting"})
@RequiresAuthentication
public class PlotSettingController {
    @Resource
    private PlotSettingService plotSettingService;

    /**
     * 根据条件查询小区信息
     * @param condition
     * @param page
     * @param limit
     * @return
     */
    @PostMapping(path = {"/list"})
    @ApiOperation(value = "小区信息列表查询", httpMethod = "POST",notes = "如果需要按照条件查询就传入condition社区名称关键字,condition是字符串类型,不是jso格式,而是K-V结构,例如：condition:阳光社区 page:2 limit:20")
    public ResponseResult list(@RequestParam(required = false) String condition,
                               @RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "18") Integer limit){
        return plotSettingService.list(condition,page,limit);
    }

    /**
     * 根据小区id查询小区的楼栋信息，单元信息，和平房/别墅信息
     * @param id
     * @return
     */
    @GetMapping(path = {"/find"})
    @ApiOperation(value = "查询单个小区信息",httpMethod = "GET",notes = "id=1")
    public ResponseResult find(@RequestParam(value = "id")String id){
        return plotSettingService.find(id);
    }
    /**
     *新增楼栋
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/save/building"})
    @ApiOperation(value = "添加楼栋", httpMethod = "POST",notes = "添加：{\"id\":\"1\",\"buildings\": [{\"storiedBuilding\": \"5栋\"}]}")
    public ResponseResult saveBuilding(@RequestBody PlotMessage plotMessage){
        return plotSettingService.saveBuilding(plotMessage);
    }
    /**
     *修改楼栋
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/update/building"})
    @ApiOperation(value = "修改楼栋", httpMethod = "POST",notes = "修改：{\"id\":\"1\",\"buildings\": [{\"id\":\"2\",\"storiedBuilding\": \"7栋\"}]}")
    public ResponseResult updateBuilding(@RequestBody PlotMessage plotMessage){
        return plotSettingService.updateBuilding(plotMessage);
    }
    /**
     *删除楼栋
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/delete/building"})
    @ApiOperation(value = "删除楼栋", httpMethod = "POST",notes = "{\"id\":\"1\",\"buildings\": [{\"id\":\"1\"}]}")
    public ResponseResult deleteBuilding(@RequestBody PlotMessage plotMessage){
        return plotSettingService.deleteBuilding(plotMessage);
    }
    /**
     * 新增单元
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/save/unit"})
    @ApiOperation(value = "新增单元", httpMethod = "POST",notes = "添加单元：{\"id\":\"1\",\"buildings\": [{\"id\": 1,\"storiedBuilding\": \"1栋\", \"units\": [{\"unit\": \"2单元\"}]}]} 修改单元：{\"id\":\"1\",\"buildings\": [{\"id\": 1,\"storiedBuilding\": \"1栋\", \"units\": [{\"id\": 1, \"unit\": \"10单元\"}]}]}")
    public ResponseResult saveUnit(@RequestBody PlotMessage plotMessage){
        return plotSettingService.saveUnit(plotMessage);
    }
    /**
     * 修改单元
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/update/unit"})
    @ApiOperation(value = "修改单元", httpMethod = "POST",notes = "添加单元：{\"id\":\"1\",\"buildings\": [{\"id\": 1,\"storiedBuilding\": \"1栋\", \"units\": [{\"unit\": \"2单元\"}]}]} 修改单元：{\"id\":\"1\",\"buildings\": [{\"id\": 1,\"storiedBuilding\": \"1栋\", \"units\": [{\"id\": 1, \"unit\": \"10单元\"}]}]}")
    public ResponseResult updateUnit(@RequestBody PlotMessage plotMessage){
        return plotSettingService.updateUnit(plotMessage);
    }
    /**
     * 删除单元
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/delete/unit"})
    @ApiOperation(value = "删除单元", httpMethod = "POST",notes = "删除单元：{\"id\":\"1\",\"buildings\": [{\"id\": 1, \"units\": [{\"id\": 1}]}]}")
    public ResponseResult deleteUnit(@RequestBody PlotMessage plotMessage){
        return plotSettingService.deleteUnit(plotMessage);
    }

    /**
     * 添加平房/别墅
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/save/villa"})
    @ApiOperation(value = "添加平房/别墅", httpMethod = "POST",notes = "添加:{\"id\":\"1\",\"bungalowVillas\": [{\"id\":\"3\",\"area\": \"A区\"}]}")
    public ResponseResult saveVilla(@RequestBody PlotMessage plotMessage){
        return plotSettingService.saveVilla(plotMessage);
    }
    /**
     * 修改平房/别墅
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/update/villa"})
    @ApiOperation(value = "修改平房/别墅", httpMethod = "POST",notes = "修改:{\"id\":\"1\",\"bungalowVillas\": [{\"id\":\"3\",\"area\": \"D区\"}]}")
    public ResponseResult updateVilla(@RequestBody PlotMessage plotMessage){
        return plotSettingService.updateVilla(plotMessage);
    }

    /**
     * 删除平房、别墅区域
     * @param plotMessage
     * @return
     */
    @PostMapping(path = {"/delete/villa"})
    @ApiOperation(value = "删除平房/别墅区域", httpMethod = "POST",notes = "删除 {\"id\":\"1\",\"bungalowVillas\": [{\"id\": \"3\"}]} ")
    public ResponseResult deleteVilla(@RequestBody PlotMessage plotMessage){
        return plotSettingService.deleteVilla(plotMessage);
    }

    /**
     * 更新保存用户修改之后的小区信息
     * @param sysPlot
     * @return
     */
    @ApiOperation(value = "更新保存小区信息",httpMethod = "POST",notes = "{\"id\":\"1\",\"householdsAvailable\":\"5000\",\"propertyName\":\"斧头帮物业\",\"propertyManager\":\"王大牛\",\"propertyPhone\":\"18756432653\"}")
    @PostMapping(path = {"/update/save"})
    public ResponseResult updateSave(@RequestBody SysPlot sysPlot, HttpServletRequest request){
        return plotSettingService.updateSave(sysPlot,request);
    }
}
